home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / pyshared / ibus / panel.py < prev    next >
Text File  |  2009-11-05  |  7KB  |  290 lines

  1. # vim:set et sts=4 sw=4:
  2. #
  3. # ibus - The Input Bus
  4. #
  5. # Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
  6. #
  7. # This library is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU Lesser General Public
  9. # License as published by the Free Software Foundation; either
  10. # version 2 of the License, or (at your option) any later version.
  11. #
  12. # This library is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public
  18. # License along with this program; if not, write to the
  19. # Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  20. # Boston, MA  02111-1307  USA
  21.  
  22. __all__ = (
  23.         "PanelBase",
  24.         "PanelItem",
  25.         "PanelButton",
  26.         "PanelToggleButton",
  27.         "PanelMenu",
  28.         "IBUS_SERVICE_PANEL",
  29.         "IBUS_PATH_PANEL"
  30.     )
  31.  
  32. IBUS_SERVICE_PANEL = "org.freedesktop.IBus.Panel"
  33. IBUS_PATH_PANEL = "/org/freedesktop/IBus/Panel"
  34.  
  35. from serializable import *
  36. from object import Object
  37. import interface
  38. import dbus
  39.  
  40. class PanelItem:
  41.     pass
  42.  
  43. class PanelButton(PanelItem):
  44.     pass
  45.  
  46. class PanelToggleButton(PanelButton):
  47.     pass
  48.  
  49. class PanelMenu(PanelItem):
  50.     pass
  51.  
  52. class PanelBase(Object):
  53.     def __init__(self, bus):
  54.         super(PanelBase, self).__init__()
  55.         self.__bus = bus
  56.         self.__proxy = PanelProxy(self, bus)
  57.  
  58.     def set_cursor_location(self, x, y, w, h):
  59.         pass
  60.  
  61.     def update_preedit_text(self, text, cursor_pos, visible):
  62.         pass
  63.  
  64.     def show_preedit_text(self):
  65.         pass
  66.  
  67.     def hide_preedit_text(self):
  68.         pass
  69.  
  70.     def update_auxiliary_text(self, text, visible):
  71.         pass
  72.  
  73.     def show_auxiliary_text(self):
  74.         pass
  75.  
  76.     def hide_auxiliary_text(self):
  77.         pass
  78.  
  79.     def update_lookup_table(self, lookup_table, visible):
  80.         pass
  81.  
  82.     def show_lookup_table(self):
  83.         pass
  84.  
  85.     def hide_lookup_table(self):
  86.         pass
  87.  
  88.     def show_candidate_window(self):
  89.         pass
  90.  
  91.     def page_up_lookup_table(self):
  92.         pass
  93.  
  94.     def page_down_lookup_table(self):
  95.         pass
  96.  
  97.     def cursor_up_lookup_table(self):
  98.         pass
  99.  
  100.     def cursor_down_lookup_table(self):
  101.         pass
  102.  
  103.     def hide_candidate_window(self):
  104.         pass
  105.  
  106.     def show_language_bar(self):
  107.         pass
  108.  
  109.     def hide_language_bar(self):
  110.         pass
  111.  
  112.     def register_properties(self, props):
  113.         pass
  114.  
  115.     def update_property(self, prop):
  116.         pass
  117.  
  118.     def focus_in(self, ic):
  119.         pass
  120.  
  121.     def focus_out(self, ic):
  122.         pass
  123.  
  124.     def state_changed(self):
  125.         pass
  126.  
  127.     def reset(self):
  128.         pass
  129.  
  130.     def start_setup(self):
  131.         pass
  132.  
  133.     def page_up(self):
  134.         self.__proxy.PageUp()
  135.  
  136.     def page_down(self):
  137.         self.__proxy.PageDown()
  138.  
  139.     def cursor_up(self):
  140.         self.__proxy.CursorUp()
  141.  
  142.     def cursor_down(self):
  143.         self.__proxy.CursorDown()
  144.  
  145.     def candidate_clicked(self, index, button, state):
  146.         self.__proxy.CandidateClicked(index, button, state)
  147.  
  148.     def property_activate(self, prop_name, prop_state):
  149.         prop_name = dbus.String(prop_name)
  150.         prop_state = dbus.Int32(prop_state)
  151.         self.__proxy.PropertyActivate(prop_name, prop_state)
  152.  
  153.     def property_show(self, prop_name):
  154.         prop_name = dbus.String(prop_name)
  155.         self.__proxy.PropertyShow(prop_name)
  156.  
  157.     def property_hide(self, prop_name):
  158.         prop_name = dbus.String(prop_name)
  159.         self.__proxy.PropertyHide(prop_name)
  160.  
  161.  
  162. class PanelProxy(interface.IPanel):
  163.     def __init__ (self, panel, bus):
  164.         super(PanelProxy, self).__init__(bus.get_dbusconn(), IBUS_PATH_PANEL)
  165.         self.__bus = bus
  166.         self.__panel = panel
  167.         self.__focus_ic = None
  168.  
  169.     def SetCursorLocation(self, x, y, w, h):
  170.         self.__panel.set_cursor_location(x, y, w, h)
  171.  
  172.     def UpdatePreeditText(self, text, cursor_pos, visible):
  173.         text = deserialize_object(text)
  174.         self.__panel.update_preedit_text(text, cursor_pos, visible)
  175.  
  176.     def ShowPreeditText(self):
  177.         self.__panel.show_preedit_text()
  178.  
  179.     def HidePreeditText(self):
  180.         self.__panel.hide_preedit_text()
  181.  
  182.     def UpdateAuxiliaryText(self, text, visible):
  183.         text = deserialize_object(text)
  184.         self.__panel.update_auxiliary_text(text, visible)
  185.  
  186.     def ShowAuxiliaryText(self):
  187.         self.__panel.show_auxiliary_text()
  188.  
  189.     def HideAuxiliaryText(self):
  190.         self.__panel.hide_auxiliary_text()
  191.  
  192.     def UpdateLookupTable(self, lookup_table, visible):
  193.         lookup_table = deserialize_object(lookup_table)
  194.         self.__panel.update_lookup_table(lookup_table, visible)
  195.  
  196.     def ShowLookupTable(self):
  197.         self.__panel.show_lookup_table()
  198.  
  199.     def HideLookupTable(self):
  200.         self.__panel.hide_lookup_table()
  201.  
  202.     def PageUpLookupTable(self):
  203.         self.__panel.page_up_lookup_table()
  204.  
  205.     def PageDownLookupTable(self):
  206.         self.__panel.page_down_lookup_table()
  207.  
  208.     def CursorUpLookupTable(self):
  209.         self.__panel.cursor_up_lookup_table()
  210.  
  211.     def CursorDownLookupTable(self):
  212.         self.__panel.cursor_down_lookup_table()
  213.  
  214.     def ShowCandidateWindow(self):
  215.         self.__panel.show_candidate_window()
  216.  
  217.     def HideCandidateWindow(self):
  218.         self.__panel.hide_candidate_window()
  219.  
  220.     def ShowLanguageBar(self):
  221.         self.__panel.show_language_bar()
  222.  
  223.     def HideLanguageBar(self):
  224.         self.__panel.hide_language_bar()
  225.  
  226.     def RegisterProperties(self, props):
  227.         props = deserialize_object(props)
  228.         self.__panel.register_properties(props)
  229.  
  230.     def UpdateProperty(self, prop):
  231.         prop = deserialize_object(prop)
  232.         self.__panel.update_property(prop)
  233.  
  234.     def FocusIn(self, ic):
  235.         self.__panel.focus_in(ic)
  236.  
  237.     def FocusOut(self, ic):
  238.         self.__panel.focus_out(ic)
  239.  
  240.     def StateChanged(self):
  241.         self.__panel.state_changed()
  242.  
  243.     def Reset(self):
  244.         self.__panel.reset()
  245.  
  246.     def StartSetup(self):
  247.         self.__panel.start_setup()
  248.  
  249.     def Destroy(self):
  250.         self.__panel.destroy()
  251.  
  252. def test():
  253.     import gtk
  254.     from bus import Bus
  255.     from inputcontext import InputContext
  256.     import factory
  257.     import attribute
  258.     import property
  259.     import text
  260.     import lookuptable
  261.  
  262.     class TestPanel(PanelBase):
  263.         def __init__(self):
  264.             self.__bus = Bus()
  265.             self.__bus.connect("disconnected", gtk.main_quit)
  266.             super(TestPanel, self).__init__(self.__bus)
  267.             self.__bus.request_name(IBUS_SERVICE_PANEL, 0)
  268.  
  269.         def focus_in(self, ic):
  270.             print "focus-in:", ic
  271.             context = InputContext(self.__bus, ic)
  272.             info = context.get_factory_info()
  273.             print "factory:", info.name
  274.  
  275.         def focus_out(self, ic):
  276.             print "focus-out:", ic
  277.  
  278.         def update_auxiliary_text(self, text, visible):
  279.             print "update-auxiliary-text:", text.text
  280.  
  281.         def update_lookup_table(self, table, visible):
  282.             print "update-lookup-table", table
  283.  
  284.     panel = TestPanel()
  285.     gtk.main()
  286.  
  287.  
  288. if __name__ == "__main__":
  289.     test()
  290.